package knoxcraft;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;

public class KnoxWorld
{
	static public void LogError(String msg)
	{
		// do nothing for now
	}

	static public IRecipe RemoveRecipe(int id)
	{
		List recipes = CraftingManager.getInstance().getRecipeList();
		int index = _GetRecipeIndex(id, recipes);
		
		if (index >= 0)
		{
			IRecipe recipe = (IRecipe)recipes.get(index);
			recipes.remove(index);
			return recipe;
		}
		else
		{	// not found
			return null;
		}
	}
	
	static public IRecipe GetRecipe(int id)
	{
		List recipes = CraftingManager.getInstance().getRecipeList();
		int index = _GetRecipeIndex(id, recipes);
		
		if (index >= 0)
			return (IRecipe)recipes.get(index);
		else
			return null;
	}

	static private int _GetRecipeIndex(int id, List recipes)
	{
		try
		{
			int size = recipes.size();
			for (int j = 0; j < size; j++)
			{
				IRecipe irecipe = (IRecipe) recipes.get(j);
				if (irecipe == null)
					continue;

				ItemStack result = irecipe.getRecipeOutput();

				if (result == null)
					continue;

				if (result.itemID == id)
					return j; // found match
			}
		}
		catch (Exception ex)
		{
		}
		return -1; // not found
	}
}
